package world.pieces;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.security.NoSuchAlgorithmException;

import javax.imageio.ImageIO;

import utility.Color;
import utility.Path;
import utility.Point;
import world.Piece;


public class Queen extends Piece implements Cloneable , Serializable{

	private boolean debug=false;
	public Queen(Color c) {
		this.color=c;
	}
	public boolean canMove(Point from, Point to) {
		if(from.getX()==to.getX() && from.getY()!= to.getY()){
			return true;
		}
		if(from.getX()!=to.getX() && from.getY()== to.getY()){
			return true;
		}
		int differenceX= from.getX()-to.getX();
		if(differenceX < 0)  differenceX=differenceX * -1;
		
		int differenceY= from.getY()-to.getY();
		if(differenceY < 0)  differenceY=differenceY * -1;
		
		if(differenceX == differenceY){
			return true;
		}
		if(debug){
			System.out.println("Queen can't move from " +from +" to "+to);
		}
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "(Queen "+color.getColor()+")"+position;
	}
	public BufferedImage get2dImage() {
		// TODO Auto-generated method stub
		if(this.color.equals(Color.WHITE)){
			try {
				return  ImageIO.read(new File(Path.getPathPiecesWhite()+"queen-white.png"));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(this.color.equals(Color.BLACK)){
			try {
				return  ImageIO.read(new File(Path.getPathPiecesBlack()+"queen-black.png"));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
	}
	@Override
	public Object clone() {
		// TODO Auto-generated method stub
		return super.clone();
	}
	@Override
	public String get2DPath() {
		if(this.color.equals(Color.WHITE)){

				return  Path.getPathPiecesWhite()+"queen-white.png";
	
		}
		else if(this.color.equals(Color.BLACK)){
			
				return  Path.getPathPiecesBlack()+"queen-black.png";

		}else{
			throw new IllegalArgumentException("Errore Il colore della regina non viene riconosciuto");
		}
	}
}
